home *** CD-ROM | disk | FTP | other *** search
/ The Utilities Experience / The Utilities Experience - Volume 1.iso / software / misc / o-z / x-windows / mesa-amiwin / src / masking.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-11-30  |  3.9 KB  |  155 lines

  1. /* $Id: masking.c,v 1.2 1995/10/30 15:33:24 brianp Exp $ */
  2.  
  3. /*
  4.  * Mesa 3-D graphics library
  5.  * Version:  1.2
  6.  * Copyright (C) 1995  Brian Paul  (brianp@ssec.wisc.edu)
  7.  *
  8.  * This library is free software; you can redistribute it and/or
  9.  * modify it under the terms of the GNU Library General Public
  10.  * License as published by the Free Software Foundation; either
  11.  * version 2 of the License, or (at your option) any later version.
  12.  *
  13.  * This library is distributed in the hope that it will be useful,
  14.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  16.  * Library General Public License for more details.
  17.  *
  18.  * You should have received a copy of the GNU Library General Public
  19.  * License along with this library; if not, write to the Free
  20.  * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  21.  */
  22.  
  23.  
  24. /*
  25. $Log: masking.c,v $
  26.  * Revision 1.2  1995/10/30  15:33:24  brianp
  27.  * added mask argument to gl_mask_[color|index]_pixels functions
  28.  *
  29.  * Revision 1.1  1995/10/13  22:40:00  brianp
  30.  * Initial revision
  31.  *
  32.  */
  33.  
  34.  
  35. /*
  36.  * Implement the effect of glColorMask and glIndexMask in software.
  37.  */
  38.  
  39.  
  40.  
  41. #include <string.h>
  42. #include "dd.h"
  43. #include "context.h"
  44. #include "macros.h"
  45. #include "masking.h"
  46. #include "pb.h"
  47.  
  48.  
  49.  
  50.  
  51. /*
  52.  * Implement glColorMask for a span of RGBA pixels.
  53.  */
  54. void gl_mask_color_span( GLuint n, GLint x, GLint y,
  55.                          GLubyte red[], GLubyte green[],
  56.                          GLubyte blue[], GLubyte alpha[] )
  57. {
  58.    GLubyte r[MAX_WIDTH], g[MAX_WIDTH], b[MAX_WIDTH], a[MAX_WIDTH];
  59.  
  60.    (*DD.read_color_span)( n, x, y, r, g, b, a );
  61.  
  62.    if ((CC.Color.ColorMask & 8) == 0) {
  63.       /* replace source reds with frame buffer reds */
  64.       MEMCPY( red, r, n );
  65.    }
  66.    if ((CC.Color.ColorMask & 4) == 0) {
  67.       /* replace source greens with frame buffer greens */
  68.       MEMCPY( green, g, n );
  69.    }
  70.    if ((CC.Color.ColorMask & 2) == 0) {
  71.       /* replace source blues with frame buffer blues */
  72.       MEMCPY( blue, b, n );
  73.    }
  74.    if ((CC.Color.ColorMask & 1) == 0) {
  75.       /* replace source alphas with frame buffer alphas */
  76.       MEMCPY( alpha, a, n );
  77.    }
  78. }
  79.  
  80.  
  81.  
  82. /*
  83.  * Implement glColorMask for an array of RGBA pixels.
  84.  */
  85. void gl_mask_color_pixels( GLuint n, const GLint x[], const GLint y[],
  86.                            GLubyte red[], GLubyte green[],
  87.                            GLubyte blue[], GLubyte alpha[],
  88.                            const GLubyte mask[] )
  89. {
  90.    GLubyte r[PB_SIZE], g[PB_SIZE], b[PB_SIZE], a[PB_SIZE];
  91.  
  92.    (*DD.read_color_pixels)( n, x, y, r, g, b, a, mask );
  93.  
  94.    if ((CC.Color.ColorMask & 8) == 0) {
  95.       /* replace source reds with frame buffer reds */
  96.       MEMCPY( red, r, n );
  97.    }
  98.    if ((CC.Color.ColorMask & 4) == 0) {
  99.       /* replace source greens with frame buffer greens */
  100.       MEMCPY( green, g, n );
  101.    }
  102.    if ((CC.Color.ColorMask & 2) == 0) {
  103.       /* replace source blues with frame buffer blues */
  104.       MEMCPY( blue, b, n );
  105.    }
  106.    if ((CC.Color.ColorMask & 1) == 0) {
  107.       /* replace source alphas with frame buffer alphas */
  108.       MEMCPY( alpha, a, n );
  109.    }
  110. }
  111.  
  112.  
  113.  
  114. /*
  115.  * Implement glIndexMask for a span of CI pixels.
  116.  */
  117. void gl_mask_index_span( GLuint n, GLint x, GLint y, GLuint index[] )
  118. {
  119.    GLuint i;
  120.    GLuint fbindexes[MAX_WIDTH];
  121.    GLuint msrc, mdest;
  122.  
  123.    (*DD.read_index_span)( n, x, y, fbindexes );
  124.  
  125.    msrc = CC.Color.IndexMask;
  126.    mdest = ~msrc;
  127.  
  128.    for (i=0;i<n;i++) {
  129.       index[i] = (index[i] & msrc) | (fbindexes[i] & mdest);
  130.    }
  131. }
  132.  
  133.  
  134.  
  135. /*
  136.  * Implement glIndexMask for an array of CI pixels.
  137.  */
  138. void gl_mask_index_pixels( GLuint n, const GLint x[], const GLint y[],
  139.                            GLuint index[], const GLubyte mask[] )
  140. {
  141.    GLuint i;
  142.    GLuint fbindexes[MAX_WIDTH];
  143.    GLuint msrc, mdest;
  144.  
  145.    (*DD.read_index_pixels)( n, x, y, fbindexes, mask );
  146.  
  147.    msrc = CC.Color.IndexMask;
  148.    mdest = ~msrc;
  149.  
  150.    for (i=0;i<n;i++) {
  151.       index[i] = (index[i] & msrc) | (fbindexes[i] & mdest);
  152.    }
  153. }
  154.  
  155.